package com.studentrecipe.mapper;

import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface MapperCreateRecipe {

    @Select("select files.file_path from ipd.files where recipe_id = #{recipeId}")
    List<String> getFileName(Integer recipeId);

    //Create recipe
    @Insert("insert into ipd.files(recipe_id, file_path)" + "values(#{recipeId}, #{filePath})")
    Integer insertFile(Integer recipeId, String filePath);

    @Insert("insert into ipd.recipes(student_id, title, description, steps, cooking_time, difficulty, cuisine, calorie_level, created_time)" +
            "values(#{userId}, #{title}, #{description}, #{steps}, #{cookingTime}, #{difficulty}, #{cuisine}, #{calorieLevel}, #{createdTime})")
    Integer insertRecipe(
            Integer userId,
            String title, String description, String steps, Integer cookingTime, String difficulty, String cuisine, String calorieLevel, LocalDate createdTime);

    @Select("select id from ipd.recipes order by id desc limit 1")
    Integer getLastRecipeId();

    Integer insertIngredient(Integer recipeId, String[] ingredient);

    Integer insertFlavor(Integer recipeId, String[] flavors);

    //Update recipe
    @Update("update ipd.recipes set " +
            "title = #{title}, description = #{description}, steps = #{steps}, cooking_time = #{cookingTime}, difficulty = #{difficulty}, cuisine = #{cuisine}, calorie_level = #{calorieLevel} where id = #{recipeId}")
    Integer updateRecipe(
            Integer recipeId,
            String title, String description, String steps, Integer cookingTime, String difficulty, String cuisine, String calorieLevel);

    //Delete recipe

    @Delete("delete from ipd.recipes where id = #{recipeId}")
    Integer deleteRecipe(Integer recipeId);

    @Delete("delete from ipd.ingredients where recipe_id = #{recipeId}")
    Integer deleteIngredient(Integer recipeId);

    @Delete("delete from ipd.flavors where recipe_id = #{recipeId}")
    Integer deleteFlavor(Integer recipeId);

    @Delete("delete from ipd.files where recipe_id = #{id}")
    Integer deleteFile(Integer id);
}
